FROM node:lts-alpine
WORKDIR /opt/build
ADD assets/package.json .
RUN yarn config set registry https://mirrors.huaweicloud.com/repository/npm/
RUN yarn install
ADD assets .
RUN set -ex&&yarn build

FROM golang:buster
WORKDIR /opt/build
COPY --from=0 /opt/build/build ./build
ADD go.mod .
RUN go env -w GO111MODULE=on&&go env -w GOPROXY=https://goproxy.cn,direct
RUN set -ex&&go mod download&&go mod download github.com/rakyll/statik&&go install github.com/rakyll/statik
RUN rm -rf statik&&statik -src=build/  -include=*.html,*.js,*.json,*.css,*.png,*.svg,*.ico,*.ttf -f
ADD . .
RUN set -ex&&go build -o agent .

FROM registry.cn-beijing.aliyuncs.com/dream-public/alpine:glibc-1643007772397
WORKDIR /opt/agent
COPY --from=1 /opt/build/agent agent
RUN set -ex&&chmod +x agent
ENTRYPOINT ["/opt/agent/agent"]